#include "../NewSyndrome-module.h"

conf *bot_info;

void
module_init (void)
{
  bot_set_auteur_module ("Thaeron");
  bot_set_desc_module ("Send entree");
  bot_set_ident_module ("entree");
  bot_set_version_module ("0.1");
  
  bot_add_type_handler ("376", "send_entree");
  bot_info = bot_conf_get_addr ();
}

#ifdef WIN32
void
init_dep (char *nom, void *addr)
{
  init_share_dep (nom, addr);
}
#endif

int
send_entree (msg * i)
{
  char buffer[203], *run_buffer;
  FILE *f;
  f = fopen (bot_info->filename, "r");
  if (!f)
    {
      log_module_info ("Fichier de config introuvable");
      return 0;
    }
  while (1)
    {
      *buffer = 0;
      fgets (buffer, 200, f);
      if (!(*buffer) && (feof (f)))
	break;
      clean_txt (buffer);
      if (strncmp (buffer, "entree=", 7))
	continue;

      run_buffer = buffer + 7;
      strcat (run_buffer, "\n");
      bot_send_raw (run_buffer);
      if (feof (f))
	break;
    }
  fclose (f);
  return 0;
}
